package br.com.sgs.bundle;

import java.util.Locale;
import java.util.ResourceBundle;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
/**
*
* @author rodrigo
*/
public class MessageBundleLoader {
 
    public static final String MESSAGE_PATH = "resources.messages";
    private static ResourceBundle messages;
 
    private static void init() {
 
        FacesContext facesContext = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(true);
               
        messages = ResourceBundle.getBundle(MESSAGE_PATH);
    }
 
    public static String getMessage(String key) {
        try {
            if (messages == null) {
                init();
            } else {
                init();
            }
            return messages.getString(key);
        } // on any failure we just return the key, which should aid in debugging.
        catch (Exception e) {
 
            return key;
        }
    }
}